# -*- coding: utf-8 -*-
'''
顾客管理使用的表单
__author__ = 'zhoubing'
'''

from django import forms
from .models import CustomerInfo
# from apps.setting.models import SysParam
from apps.app_setting.models import SysParam


class AddCustomerForm(forms.ModelForm):
    """
    添加客人信息类
    """

    # 外键过滤
    def __init__(self, *args, **kwargs):
        super(AddCustomerForm, self).__init__(*args, **kwargs)
        # access object through self.instance...
        self.fields['customer_gender'].queryset = SysParam.objects.filter(
            param_value__lte='100102')
        self.fields['customer_source'].queryset = SysParam.objects.filter(
            param_value__contains='1002')

    class Meta:
        model = CustomerInfo  # 指定要对照的ORM类
        default_class = {'class': 'layui-input'}

        # 指定关联哪些字段
        # fields = ('title','authors','publisher','publication_date')
        exclude = (
            'create_date', 'customer_type', 'customer_store_name',
            'buy_card_mark', 'customer_state', 'introducer_mark'
        )  # 也可以指定不关联哪些字段.

        help_texts = {
            'introducer_customer': '填写由哪个客人推荐',
        }

        widgets = {
            'customer_name': forms.TextInput(attrs=default_class),
            'customer_gender': forms.Select(attrs=default_class),
            'customer_birthday': forms.DateInput(attrs={
                'placeholder': '请选取顾客生日',
                'class': 'layui-input date-item',
                'autocomplete':'off', 'readonly':'true',
                'id': 'c_birthday'
            }),
            'customer_joindate': forms.DateInput(attrs={
                'placeholder': '请选取顾客加入日期',
                'class': 'layui-input date-item',
                'autocomplete': 'off', 'readonly': 'true',
                'id': 'c_join_date',
            }),
            'customer_mobile': forms.TextInput(attrs=default_class),
            'customer_tel': forms.TextInput(attrs=default_class),
            'customer_qq': forms.TextInput(attrs=default_class),
            'customer_email': forms.TextInput(attrs=default_class),
            'customer_weixin': forms.TextInput(attrs=default_class),
            'introducer_customer': forms.TextInput(attrs=default_class),
            'introducer_mark': forms.CheckboxInput(attrs=default_class),
            'customer_vocation': forms.TextInput(attrs=default_class),
            'customer_source': forms.Select(attrs=default_class),
            'customer_memo': forms.Textarea(attrs={
                'placeholder': '请输入顾客备注信息',
                'class': 'layui-textarea'
            }),
        }
        # 之前在字段里定义的属性,这里就可以单独拿出来定义了
        error_messages = {
            'customer_name': {'required': u'姓名不能为空', 'invalid': u'书名书写错误'},
        }
